<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!--
	picnikbox_close_2_0.html
	
	This is a sample "close" file for a PicnikBox application. You will need to modify this file.
	This code can be freely copied, modified, and distributed.  
	
	To create a fully-functional application, you'll probably need to generate this file
	via a server-side script.  That script would be responsible for handling the results
	of the Picnik export operation (eg., saving the exported files).  After saving, that
	script would generate the appropriate javascript (see below) to tell the parent iframe
	to update its user interface.
-->
<html>
<!--
Copyright 2011 Google Inc. All Rights Reserved.

Use of this source code is governed by an Apache 2.0 License.
See the COPYING file for details.
-->
<head>
<script language="javascript" type="text/javascript">
function close() {

	// Check to see if we are still in an iframe.  
	//
	// If we are still inside an iframe, then we can invoke some Javascript and tell the parent
	// to (a) refresh and (b) close the Picnik window.  
	// 
	// If we are not inside an iframe, then redirect back to the appropriate page on our website.  
	// In this case, you'll need to pass in the appropriate context (via sessions, cookies, 
	// URL params, etc.) to put the client back into the same state as it was in before launching Picnik.
	
	if (parent.frames.length > 0) {		
		// (a) Create a javascript command to tell the parent to refresh.  This is application dependent
		// and will most likely be generated by your server-side script.

		// (b) Let the parent frame close the picnik in a box frame.
		// Firefox doesn't like us closing the doc while we're in the onload callback 
		// (it'll stay stuck in the loading state), so set a very short timeout
		// to break out of this call stack.
		setTimeout( "parent.onPicnikClose()", 10 );
    } else {
		// Sometimes Picnik in a box may leave the box (e.g. authenticating to Flickr)
		// In this case, the user leaves your site and ends up back on Picnik.com.
		// They are then no longer in a frame when they hit close.
		// In this case, you should redirect to an appropriate page on your site
		document.location.replace('/');
    }
}
</script>
</head>
<body onload="close()">
</body>
</html>
